package com.huan.iteye.quartz;

import com.huan.iteye.service.QuartzJobCfgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * quartz job 初始化
 *
 * @author huan.fu
 * @date 2018/9/10 - 17:11
 */
@Component
@Slf4j
public class QuartzJobLoader implements InitializingBean {

	@Autowired
	private QuartzJobCfgService quartzJobCfgService;
	@Autowired
	private QuartzService quartzService;

	@Override
	public void afterPropertiesSet() {
		log.info("开始加载quartz定时任务");
		quartzJobCfgService
				.findAll()
				.forEach(job -> quartzService.addQuartzJob(job));
		log.info("完成加载quartz定时任务");
	}
}
